package com.hdaccp.dao.impl;

import com.hdaccp.dao.CapitalDao;
import com.hdaccp.dao.CommonDao;
import com.hdaccp.entity.Capital;
import com.hdaccp.util.BaseDao;

import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

public class CapitalDaoimpl extends BaseDao implements CommonDao,CapitalDao {
    @Override
    public List getAll() {
        return null;
    }

    @Override
    public Object getById(Serializable id) {
        return null;
    }

    @Override
    public boolean add(Object entity) {
        return false;
    }

    @Override
    public boolean update(Object entity) {
        return false;
    }

    @Override
    public boolean deleteById(Serializable id) {
        return false;
    }

	@Override
	public Capital getYC(int zid) {
		// TODO Auto-generated method stub
		String sql="select * from capital where zid=?";
		Object [] params={zid};
		ResultSet rs=super.executeQuery(sql, params);
		Capital c=new Capital();
		try {
			if(rs.next()){
				c.setId(rs.getInt(1));
				c.setCamount(rs.getFloat(2));
				c.setSum(rs.getFloat(3));
				c.setZid(rs.getInt(4));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				super.closeAll(rs, rs.getStatement(), rs.getStatement().getConnection());
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return c;
	}

	@Override
	public boolean updYC(Capital c) {
		// TODO Auto-generated method stub
		String sql="update capital set `sum`=? where id=?";
		Object [] params={c.getSum(),c.getId()};
		return super.executeUpdate(sql, params);
	}

	@Override
	public boolean updYXT(Capital c) {
		// TODO Auto-generated method stub
		String sql="update capital set camount=?,`sum`=? where zid=?";
		Object [] params={c.getCamount(),c.getSum(),c.getZid()};
		return super.executeUpdate(sql, params);
	}
}
